package com.greenway.beans.clickstates;

import java.io.IOException;

import org.primefaces.event.map.PointSelectEvent;
import org.primefaces.json.JSONException;
import org.primefaces.model.map.LatLng;
import org.primefaces.model.map.MapModel;
import org.primefaces.model.map.Marker;

import com.greenway.beans.MapBean;

public class AddWaypointState implements State {

	private MapBean mapBean;

	public AddWaypointState(MapBean mapBean) {
		this.mapBean = mapBean;
	}
	
	@Override
	public void handleMarker(PointSelectEvent event, MapModel mapModel) throws IOException, JSONException {
		
		LatLng latlng = event.getLatLng();
		
		Integer markerId = mapBean.getMarkerId();
		
		//Create start marker
		Marker markerFinish = new Marker(latlng, "" + markerId++);
		markerFinish.setDraggable(true);
		mapModel.addOverlay(markerFinish);
		
		mapBean.drawRout();
				
	}

}
